package n7.restaurant.java.Swing;

import java.awt.Color;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Iterator;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

import n7.restaurant.java.Entity.Apprendi;
import n7.restaurant.java.Entity.Chef;
import n7.restaurant.java.Entity.Client;
import n7.restaurant.java.Entity.Ingredient;
import n7.restaurant.java.Entity.Porte;
import n7.restaurant.java.Entity.Position;
import n7.restaurant.java.Entity.Serveur;
import n7.restaurant.java.Enum.Acces;


public class AfficheurFixe extends JPanel {

	public static final int LARGEUR_IMG_SERVEUR = 25;
	public static final int LARGEUR_IMG_CLIENT = 25;
	public static final int LARGEUR_IMG_GRAND_CHEF = 25;
	public static final int LARGEUR_IMG_INGREDIENT = 25;
	public static final int LARGEUR_IMG_SPECIALISTE = 25;

	private static final long serialVersionUID = 1L;

	public AfficheurFixe() {
		super();
		setPreferredSize(new Dimension(910, 610));
	}

	public void paintComponent(Graphics g) {
		// Dessiner le fond du composant
		g.setColor(Color.white);
		g.fillRect(0, 0, getWidth(), getHeight());
		paintSalles(g);
		paintPortes(g);
		paintClients(g);
		paintSpecialistes(g);
		paintIngredients(g);
		paintServeurs(g);
		paintApprendis(g);
		paintGrandChef(g);
	}

	public void paintIngredients(Graphics g) {
		Image image = null;
		for (Iterator<Ingredient> i = Ingredient.ingredients.iterator(); i
				.hasNext();) {
			Ingredient in = i.next();
			if (in.getNom().equals("tomate")) {
				ImageIcon icon_tomate = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/tomate.png"));
				icon_tomate.setImage(icon_tomate.getImage().getScaledInstance(
						30, 30, Image.SCALE_DEFAULT));
				Image image_tomate = icon_tomate.getImage();
				image = image_tomate;
			} else if (in.getNom().equals("cafe")) {
				ImageIcon icon_cafe = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/cafe.png"));
				icon_cafe.setImage(icon_cafe.getImage().getScaledInstance(30,
						30, Image.SCALE_DEFAULT));
				Image image_cafe = icon_cafe.getImage();
				image = image_cafe;
			} else if (in.getNom().equals("bacon")) {
				ImageIcon icon_bacon = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/bacon.png"));
				icon_bacon.setImage(icon_bacon.getImage().getScaledInstance(30,
						30, Image.SCALE_DEFAULT));
				Image image_bacon = icon_bacon.getImage();
				image = image_bacon;
			} else if (in.getNom().equals("carotte")) {
				ImageIcon icon_carotte = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/carotte.png"));
				icon_carotte.setImage(icon_carotte.getImage()
						.getScaledInstance(30, 30, Image.SCALE_DEFAULT));
				Image image_carotte = icon_carotte.getImage();
				image = image_carotte;
			} else if (in.getNom().equals("champignon")) {
				ImageIcon icon_champignon = new ImageIcon(getClass()
						.getResource("/n7/restaurant/java/Pic/champignon.png"));
				icon_champignon.setImage(icon_champignon.getImage()
						.getScaledInstance(30, 30, Image.SCALE_DEFAULT));
				Image image_champignon = icon_champignon.getImage();
				image = image_champignon;
			} else if (in.getNom().equals("choux_blanc")) {
				ImageIcon icon_choux_blanc = new ImageIcon(getClass()
						.getResource("/n7/restaurant/java/Pic/choux_blanc.png"));
				icon_choux_blanc.setImage(icon_choux_blanc.getImage()
						.getScaledInstance(30, 30, Image.SCALE_DEFAULT));
				Image image_choux_blanc = icon_choux_blanc.getImage();
				image = image_choux_blanc;
			} else if (in.getNom().equals("citron")) {
				ImageIcon icon_citron = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/citron.png"));
				icon_citron.setImage(icon_citron.getImage().getScaledInstance(
						30, 30, Image.SCALE_DEFAULT));
				Image image_citron = icon_citron.getImage();
				image = image_citron;
			} else if (in.getNom().equals("creme")) {
				ImageIcon icon_creme = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/creme.png"));
				icon_creme.setImage(icon_creme.getImage().getScaledInstance(30,
						30, Image.SCALE_DEFAULT));
				Image image_creme = icon_creme.getImage();
				image = image_creme;
			} else if (in.getNom().equals("lait")) {
				ImageIcon icon_lait = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/lait.png"));
				icon_lait.setImage(icon_lait.getImage().getScaledInstance(30,
						30, Image.SCALE_DEFAULT));
				Image image_lait = icon_lait.getImage();
				image = image_lait;
			} else if (in.getNom().equals("mozzarella")) {
				ImageIcon icon_mozzarella = new ImageIcon(getClass()
						.getResource("/n7/restaurant/java/Pic/mozzarella.png"));
				icon_mozzarella.setImage(icon_mozzarella.getImage()
						.getScaledInstance(30, 30, Image.SCALE_DEFAULT));
				Image image_mozzarella = icon_mozzarella.getImage();
				image = image_mozzarella;
			} else if (in.getNom().equals("oeuf")) {
				ImageIcon icon_oeuf = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/oeuf.png"));
				icon_oeuf.setImage(icon_oeuf.getImage().getScaledInstance(30,
						30, Image.SCALE_DEFAULT));
				Image image_oeuf = icon_oeuf.getImage();
				image = image_oeuf;
			} else if (in.getNom().equals("oignon")) {
				ImageIcon icon_oignon = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/oignon.png"));
				icon_oignon.setImage(icon_oignon.getImage().getScaledInstance(
						30, 30, Image.SCALE_DEFAULT));
				Image image_oignon = icon_oignon.getImage();
				image = image_oignon;
			} else if (in.getNom().equals("poivron_jaune")) {
				ImageIcon icon_poivron_jaune = new ImageIcon(getClass()
						.getResource("/n7/restaurant/java/Pic/poivron_jaune.png"));
				icon_poivron_jaune.setImage(icon_poivron_jaune.getImage()
						.getScaledInstance(30, 30, Image.SCALE_DEFAULT));
				Image image_poivron_jaune = icon_poivron_jaune.getImage();
				image = image_poivron_jaune;
			} else if (in.getNom().equals("poivron_rouge")) {
				ImageIcon icon_poivron_rouge = new ImageIcon(getClass()
						.getResource("/n7/restaurant/java/Pic/poivron_rouge.png"));
				icon_poivron_rouge.setImage(icon_poivron_rouge.getImage()
						.getScaledInstance(30, 30, Image.SCALE_DEFAULT));
				Image image_poivron_rouge = icon_poivron_rouge.getImage();
				image = image_poivron_rouge;
			} else if (in.getNom().equals("poivron_vert")) {
				ImageIcon icon_poivron_vert = new ImageIcon(getClass()
						.getResource("/n7/restaurant/java/Pic/poivron_vert.png"));
				icon_poivron_vert.setImage(icon_poivron_vert.getImage()
						.getScaledInstance(30, 30, Image.SCALE_DEFAULT));
				Image image_poivron_vert = icon_poivron_vert.getImage();
				image = image_poivron_vert;
			} else if (in.getNom().equals("pomme")) {
				ImageIcon icon_pomme = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/pomme.png"));
				icon_pomme.setImage(icon_pomme.getImage().getScaledInstance(30,
						30, Image.SCALE_DEFAULT));
				Image image_pomme = icon_pomme.getImage();
				image = image_pomme;
			} else if (in.getNom().equals("rouget")) {
				ImageIcon icon_rouget = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/rouget.png"));
				icon_rouget.setImage(icon_rouget.getImage().getScaledInstance(
						30, 30, Image.SCALE_DEFAULT));
				Image image_rouget = icon_rouget.getImage();
				image = image_rouget;
			} else {
				ImageIcon icon_veau = new ImageIcon(getClass().getResource(
						"/n7/restaurant/java/Pic/veau.png"));
				icon_veau.setImage(icon_veau.getImage().getScaledInstance(30,
						30, Image.SCALE_DEFAULT));
				Image image_veau = icon_veau.getImage();
				image = image_veau;
			}

			g.drawImage(image, 10 * in.getPosition().getX(), 600 - 10 * in
					.getPosition().getY(), this);
		}
	}

	/**
	 * Dessiner les Client
	 * 
	 * @param Graphics
	 *            g
	 * */
	public void paintClients(Graphics g) {
		ImageIcon icon = new ImageIcon(getClass()
				.getResource("/n7/restaurant/java/Pic/client.png"));
		icon.setImage(icon.getImage().getScaledInstance(30, 30,
				Image.SCALE_DEFAULT));
		Image image = icon.getImage();
		for (Iterator<Client> i = Client.clients.iterator(); i.hasNext();) {
			Client a = i.next();
			g.drawImage(image, 10 * a.getPosition().getX(), 600 - 10 * a
					.getPosition().getY(), this);
			a.setPosition(new Position(a.getPosition().getX(), a
					.getPosition().getY(), Acces.SALLE_PRINCIPALE));
		}
	}

	public void paintSpecialistes(Graphics g) {
		// Dessiner les specialistes
		ImageIcon icon = new ImageIcon(getClass().getResource("/n7/restaurant/java/Pic/chef.png"));
		icon.setImage(icon.getImage().getScaledInstance(50, 50,
				Image.SCALE_DEFAULT));
		Image image = icon.getImage();
		for (Iterator<n7.restaurant.java.Entity.Specialiste> i = n7.restaurant.java.Entity.Specialiste.specialistes.iterator(); i
				.hasNext();) {
			n7.restaurant.java.Entity.Specialiste s = i.next();
			g.drawImage(image, 10 * s.getPosition().getX(), 600 - 10 * s
					.getPosition().getY(), this);
		}
	}

	public void paintPortes(Graphics g) {
		// Dessiner les portes
		g.setColor(Color.RED);
		for (Iterator<n7.restaurant.java.Entity.Porte> i = Porte.portes.iterator(); i.hasNext();) {
			Porte p = i.next();

			g.drawLine(10 * p.getX1(), 600 - 10 * p.getY1(), 10 * p.getX2(),
					600 - 10 * p.getY2());
		}
	}

	public void paintSalles(Graphics g) {
		g.setColor(Color.blue);
		g.drawRect(0, 0, 900, 600);
		g.drawLine(300, 0, 300, 600);
		g.drawLine(300, 200, 900, 200);
		g.drawLine(500, 0, 500, 200);
		g.drawLine(700, 0, 700, 200);
	}

	public void paintServeurs(Graphics g) {
		ImageIcon icon = new ImageIcon(getClass().getResource(
				"/n7/restaurant/java/Pic/serveur.png"));
		icon.setImage(icon.getImage().getScaledInstance(50, 50,
				Image.SCALE_DEFAULT));
		Image image = icon.getImage();
		for (Iterator<Serveur> i = Serveur.serveurs.iterator(); i.hasNext();) {
			Serveur s = i.next();
			g.drawImage(image, 10 * s.getPosition().getX(), 600 - 10 * s
					.getPosition().getY(), this);
		}
	}
	
	public void paintApprendis(Graphics g) {
		ImageIcon icon = new ImageIcon(getClass().getResource(
				"/n7/restaurant/java/Pic/apprendi.png"));
		icon.setImage(icon.getImage().getScaledInstance(50, 50,
				Image.SCALE_DEFAULT));
		Image image = icon.getImage();
		for (Iterator<Apprendi> i = Apprendi.apprendis.iterator(); i.hasNext();) {
			Apprendi s = i.next();
			g.drawImage(image, 10 * s.getPosition().getX(), 600 - 10 * s
					.getPosition().getY(), this);
		}
	}

	public void paintGrandChef(Graphics g) {
		ImageIcon icon = new ImageIcon(getClass().getResource(
				"/n7/restaurant/java/Pic/grand_chef.png"));
		icon.setImage(icon.getImage().getScaledInstance(50, 50,
				Image.SCALE_DEFAULT));
		Image image = icon.getImage();
		g.drawImage(image, 10 * Chef.grand_chef.getPosition().getX(),
				600 - 10 * Chef.grand_chef.getPosition().getY(), this);
	}
}